﻿using System;
using System.Collections.Generic;
using System.Text;
using OVS.CoreDomain.Data;
using OVS.CoreDomain;
using System.Data;

namespace OVS.Data
{
    public class DalWard : Dal<IWard, Ward>, IDalWard
    {

        private const string SP_GET_WARDS = "usp_GetWards";

        private readonly IDalManager _manager;
        private static readonly IDalWard _instance = new DalWard();

        public static IDalWard Instance
        {
            get { return _instance; }
        }

        public DalWard()
        {
            _manager = new DalManager();
        }

        public DalWard(IDalManager manager)
        {
            _manager = manager;
        }

        protected override void Convert(IWard obj, DataRow row)
        {
            obj.WardId = _manager.GetValue<string>(row, "WardNo");
            obj.WardName = _manager.GetValue<string>(row, "WardName");
            obj.PanchayatId = _manager.GetValue<string>(row, "PanchayatId");

        }

        public IList<IWard> GetWards(string panchayatId)
        {
            _manager.StoredProcedureName = SP_GET_WARDS;
            _manager.AddInParameter("@PanchayatId", DbType.String, panchayatId);
            List<IWard> wards = new List<IWard>();
            foreach (IWard ward in ConvertAll(_manager.ExecuteDataSet()))
                wards.Add(ward);
            return wards;
        }

       
    }
}
